"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.recording = void 0;
const config_1 = require("../../config/config");
const Member_1 = require("../../lib/Member");
async function recording(app, io) {
    const { socket } = app.locals;
    const { userId } = socket.handshake.query;
    if (!socket.startRecord) {
        socket.startRecord = async function startRecord(classroom) {
            var _a, _b;
            const { clientUtils } = app.locals;
            const suffix = ((_b = (_a = classroom.mediaOptions) === null || _a === void 0 ? void 0 : _a.mediaConstraints) === null || _b === void 0 ? void 0 : _b.video) ? 'mp4' : 'webm';
            const recordFilename = `${Date.now()}.${suffix}`;
            const __url = `file://${config_1.lConfig.recordingDirectory}/${recordFilename}`;
            const owner = Member_1.Members.get(userId);
            try {
                const recorderEndpoint = await clientUtils.createRecordEndpoint(classroom.pipeline, __url);
                await owner.startRecord(classroom.classId, recorderEndpoint);
            }
            catch (error) {
                socket.emit('recording:error', error);
            }
            return __url;
        };
    }
}
exports.recording = recording;
